export default {
  getOrdSta(val) {
    return (
      {
        0: "待支付",
        1: "备货中",
        2: "待发货",
        3: "已发货",
        4: "待签收",
        6: "已签收",
        7: "转售中",
        8: "已转售",
        11: "退款中",
        12: "已退款",
        21: "已取消",
        31: "已认养",
      }[val * 1] || "处理中"
    );
  },
  getIndexShare(by_uid) {
    return {
      title: "认养一棵榴莲树",
      path: "/pages/index/index?by_uid=" + (by_uid || ""),
      // imageUrl: "/static/img/home-share.jpg",
    };
  },
  isEqualObj(obj1, obj2) {
    return JSON.stringify(obj1) == JSON.stringify(obj2);
  },
  queryParams(obj, ...args) {
    for (const key in obj) {
      let val = obj[key];
      if (typeof val == "string") val = encodeURIComponent(val);
      obj[key] = val;
    }
    return uni.$u.queryParams(obj, ...args);
  },
  decodeParams(body) {
    for (const key in body) {
      const val = body[key];
      try {
        if (val && typeof val == "string") {
          body[key] = decodeURIComponent(val);
        }
      } catch (error) {
        console.log(error.message, val);
      }
    }
  },
  getChanged(row, prev) {
    let changed = {};
    for (const key in row) {
      if (row[key] !== prev[key]) {
        changed[key] = row[key];
      }
    }
    if (!Object.keys(changed).length) {
      return false;
    }
    return changed;
  },
};
